<!--   
Persistent Digital Archives and Library System (PeDALS) 
(c) 2008 - All Rights Reserved
//-->
<?php include 'includes/config.php'; 
$term = urldecode(@$_GET["prov"]);
/* query string not correct */
if ($term == "") {
	echo "Provenance not found.  You did not select a valid provenance for viewing.";
	die;
}
$params = array(&$term);	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="Persistent Digital Archives and Library System" />
<title>PeDALS Web Administration</title>
<link rel="shortcut icon" href="images/favicon.ico" />
<link href="includes/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php include 'includes\header.php'; ?>
<div id="breadcrumb-container">
  <div id="breadcrumb"><a href="index.php" title="Home page">Home</a> / <a href="provSummary.php" title="Provenances">Provenances</a> / Provenance Detail</div>
  <div id="breadcrumb-side"><form name="search" action="search.php"><input type="text" name="q" width="50"/><input type="submit" value="Go" /></form><a href="advSearch.php" title="Advanced Search" alt="Advanced Search">Advanced Search</a>
  </div>
  <div class="clear"></div>
</div>
<!-- 
  CONTENT
  -->
<div id="content-container">
  <!-- 
	SIDE COLUMN
	-->
  <div id="content-side">
    <ul class="link-list-vertical">
      <li><a href="provSummary.php" title="View a list of all provenances in PeDALS.">List Provenances</a></li>
      <li><a href="provNew.php" title="Add a provenance to PeDALS.">Add Provenance</a></li>
 <li><br/>
	<li><?php echo "<a title=\"Edit\"";
		echo " alt=\"Edit\"";
		echo " href=provEdit.php?prov=".$term."";
		echo ">Edit this information</a><br/>";		
		?>
        <li><?php
		echo "<a title=\"Add series\"";
		echo " alt=\"Add series\"";
		echo " href=serNew.php?prov=".$term."";
		echo ">Add series</a><br/>";		
		?>
    </ul>
  </div>
  <!-- 
	MAIN COLUMN
	-->
  <div id="content"><a name="maincontent" id="maincontent"></a>
  
  <?php
	/* Create the statement. */
	$tsqlProv = "SELECT TOP 1 ProvenanceId, ProvenanceName, ProvenanceAdministrativeHistory, ProvenanceGeneralNote, CONVERT(VARCHAR, CreatedDate, 101) AS CreatedDate, CreatedBy, CONVERT(VARCHAR, ModifiedDate, 101) AS ModifiedDate, ModifiedBy FROM Provenance WHERE ProvenanceId = (?)";

	$getData = sqlsrv_prepare( $conn, $tsqlProv, $params);
	if( $getData === false ) {
		 echo "Error in preparing statement.<br/><br/><br/><br/>\n";
		 die;
	}
	
	
	/* Execute the statement. Display any errors that occur. */
	if( sqlsrv_execute( $getData))
	{   
	/*echo "Statement executed.\n";*/
	}
	else
	{
		 echo "Error in executing statement.<br/><br/><br/><br/>\n";
		 die;
	}
	$rowCount = 0;
	while (sqlsrv_fetch( $getData ))
	{	
		$id = sqlsrv_get_field($getData, 0);
		$name = sqlsrv_get_field($getData, 1);
		$createdon = sqlsrv_get_field($getData, 4);
		$createdby = sqlsrv_get_field($getData, 5);
		$modifiedon = sqlsrv_get_field($getData, 6);
		$modifiedby = sqlsrv_get_field($getData, 7);
		$rowCount++;
	}
	
	/* provenance id in query string is wrong */
	if( $rowCount == 0 ) { 
	echo "Provenance not found.  You did not select a valid provenance for viewing.<br/><br/><br/><br/>";
	die;
    	}	
	   ?> 
    <h1><?php echo $name; ?></h1>
    
<p><strong>Administrative History</strong>:<br/> 
<?php 
$tsqlAH = "SELECT ProvenanceAdministrativeHistory FROM Provenance WHERE ProvenanceId = (?)";
$stmt = sqlsrv_query( $conn, $tsqlAH, $params);

while ($rr=sqlsrv_fetch_array($stmt, SQLSRV_FETCH_BOTH)){
	echo $rr[0];
}
 ?></p>
<p><strong>General Note</strong>:<br/> 
<?php 
$tsqlAH = "SELECT ProvenanceGeneralNote FROM Provenance WHERE ProvenanceId = (?)";
$stmt = sqlsrv_query( $conn, $tsqlAH, $params);

while ($rr=sqlsrv_fetch_array($stmt, SQLSRV_FETCH_BOTH)){
	echo $rr[0];
}
 ?></p>

        <table class="table" border="1" cellspacing="0" summary="Table listing all the variant names for this provenance">
      <thead>
        <tr>
          <th scope="col" width="25%">Type of Variant</th>
          <th scope="col">Variant for Name</th>
        </tr>
      </thead>
 
      <tbody>
<?php	
	$tsqlVar = "SELECT Qualifier.QualifierType, ProvenanceVariant.ProvenanceVariantName FROM ProvenanceVariant INNER JOIN Qualifier ON ProvenanceVariant.QualifierId = Qualifier.QualifierId WHERE ProvenanceVariant.ProvenanceId = (?) ORDER BY Qualifier.QualifierType, ProvenanceVariant.ProvenanceVariantName";   
	/* Create the statement. */

	$getData = sqlsrv_prepare( $conn, $tsqlVar, $params);
	if( $getData )
	{ 	}
	else
	{
		 echo "Error in preparing statement.\n";
		 die;
	}

	/* Execute the statement. Display any errors that occur. */
	if( sqlsrv_execute( $getData))
	{ 	
	} else {
		 echo "Error in executing statement.<br/><br/><br/><br/>\n";
		 die;
	}
	$rowCount = 0;
	
	/* Show list of variant names */
	while (sqlsrv_fetch( $getData ))
	{
		$varQual = sqlsrv_get_field($getData, 0);
		$varName = sqlsrv_get_field($getData, 1);
		echo "<tr><td>".$varQual."</td><td>".$varName."</td></tr>";
	
		$rowCount++;
    }	

	/* If variant names are not found */
	if( $rowCount == 0 ) { 
	    echo "<tr><td colspan=\"2\">There are no variant names yet.</td></tr>"; 
    	}
	
?>
	</tbody>
	</table><br/>
<p><strong>Series</strong>:<br/>

<?php	
	$tsql = "SELECT Series.SeriesTitle, Series.SeriesId, Provenance.ProvenanceId
         FROM Series LEFT OUTER JOIN
         	Provenance ON Series.ProvenanceId = Provenance.ProvenanceId
			WHERE   Provenance.ProvenanceId = (?)
         ORDER BY Series.SeriesTitle";

	/* Create the statement. */
	$getData = sqlsrv_prepare( $conn, $tsql, $params);
	if( $getData )
	{ 	}
	else
	{
		 echo "Error in preparing statement.<br/><br/><br/><br/>\n";
		 die;
	}

	/* Execute the statement. Display any errors that occur. */
	if( sqlsrv_execute( $getData))
	{ 	}
	else
	{
		 echo "Error in executing statement.<br/><br/><br/><br/>\n";
		 die;
	}
	
	/* Start rowCount in case there are no results */
	$rowCount = 0;
	
	/* Create list of series */
	while (sqlsrv_fetch( $getData ))
	{
		$seriestitle = sqlsrv_get_field($getData, 0);
		$seriesid = sqlsrv_get_field($getData, 1);
		
		echo "<a title=\"".$seriestitle."\"";
		echo " alt=\"".$seriestitle."\"";
		echo " href=serDetail.php?ser=".$seriesid."";
		echo ">".$seriestitle."</a>";
		echo "<br/>";	
			
		$rowCount++;
    }	

	/* When no series are found */
	if( $rowCount == 0 ) { 
	    echo "There are no series yet."; 
    	}

/* Free the statement and connection resources. */	
    sqlsrv_free_stmt( $getData );	
	sqlsrv_close( $conn);

?>              
</p>    
<p><strong>Actions</strong>:<br/>
		<?php
		echo "<a title=\"Edit\"";
		echo " alt=\"Edit\"";
		echo " href=provEdit.php?prov=".$id."";
		echo ">Edit this information</a><br/>";		
		?>
        <?php
		echo "<a title=\"Add series\"";
		echo " alt=\"Add series\"";
		echo " href=serNew.php?prov=".$id."";
		echo ">Add series</a><br/>";		
		?>
        </p>

      <p><strong>Properties</strong>:<br/>
      Created by <?php echo $createdby; ?> on <?php echo $createdon; ?><br/>
      <?php
	  if ($modifiedby != "") {
      	echo "Modified by ".$modifiedby." on ".$modifiedon;
	  }
	?>

<?php include 'includes\footer.php'; ?>
  </div>

</div>
<?php

?>
</body>
</html>
